* MechanismsVoterTurnout
** Goal: examine voter turnout data
** Beatrice Lee
** Date Created: 2024-05-23
** Last Updated: 2024-07-11 // bal

cd "$Data/Processing"
use state_elections_panel_df5_20240709, clear

*************************************** DEP VAR MEANS ********************************************
sum inc_turnout_vep top_nic_turnout_vep total_turnout_vep if year >= 2020
sum inc_turnout_vep top_nic_turnout_vep total_turnout_vep if year > 2012

****************************** voter turnout (log of votes/vep) **********************

eststo clear

*1) 2sls --------------------------------------------------------------------
* inc party votes / vep
eststo: ivregress 2sls inc_turnout_vep inc_turnout_vep_prev norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

* non-inc party votes / vep
eststo: ivregress 2sls top_nic_turnout_vep top_nic_turnout_vep_prev norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

* total party votes / vep
eststo: ivregress 2sls total_turnout_vep total_turnout_vep_prev norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

**** Export Table to Latex
cd "$Results"
esttab using "voter_turnout_2sls_20240709.tex", replace /// Replace file if it already exists
 collabels("\multicolumn{1}{c}{1l}" "\multicolumn{1}{c}{l2}" "\multicolumn{1}{c}{l3}" "\multicolumn{1}{c}{l4}" "\multicolumn{1}{c}{l5}" "\multicolumn{1}{c}{l6}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"\(F\)"')) drop(_cons) ///
 booktabs ///
 title("Voter Turnout 2sls") ///
 addnotes("Note: TKTKTKTK")

 *2) panel -------------------------------------------------------------------------

eststo clear

//////////////////////// outcome 1 = Total votes inc party/VEP
*** no controls, no fes
eststo: reg inc_turnout_vep c.reps_per_million##i.duringpandemic if year > 2012 , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

** all fes
eststo: reghdfe inc_turnout_vep c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

//////////////////////// outcome 2 = Total votes top non inc party/VEP
*** no controls, no fes
eststo: reg top_nic_turnout_vep c.reps_per_million##i.duringpandemic if year > 2012 , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

** all fes
eststo: reghdfe top_nic_turnout_vep c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

//////////////////////// outcome 3 = Total votes/VEP
*** no controls, no fes
eststo: reg total_turnout_vep c.reps_per_million##i.duringpandemic if year > 2012 , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

** all fes
eststo: reghdfe total_turnout_vep c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

****** Export Table to Latex
cd "$Results/"
esttab using "voter_turnout_panel_20240709.tex", replace ///
 collabels("\multicolumn{1}{c}{col1}" "\multicolumn{1}{c}{col2}" "\multicolumn{1}{c}{col3}" "\multicolumn{1}{c}{col4}" "\multicolumn{1}{c}{col5}" "\multicolumn{1}{c}{col6}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 office_fe year_fe state_fe norm_vote_year_fe office_state_fe, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"Office FE"' `"Year FE"' `"State FE"' `"Normal Vote x Year FE"' `"Office x State FE"')) drop(_cons) ///
 booktabs /// 
 title("Voter Turnout panel") ///
 addnotes("Note: TKTKTKTK")